//
// RTSPServerSession.h
//
// $Id: //base/include/RTSPServerSession.h
//
// Library: base
// Package: base
// Module : RTSPServerSession
// Author :	Jelin,doitsjz@163.com
// Date	  :	10/30/2012
// 
// Definition of the RTSPServerSession class.
//
// Copyright (c) 2012-2012, iGuard.
//


#ifndef RTSPServerSession_INCLUDED
#define RTSPServerSession_INCLUDED


/**
	RTSPServerSession class for recving RTSP Request 
	and sending RTSP Response
*/
/*
A.2 Server State Machine

   The server can assume the following states:

   Init:
          The initial state, no valid SETUP has been received yet.

   Ready:
          Last SETUP received was successful, reply sent or after
          playing, last PAUSE received was successful, reply sent.

   Playing:
          Last PLAY received was successful, reply sent. Data is being
          sent.

   Recording:
          The server is recording media data.

state           message received  next state
     Init            SETUP             Ready
                     TEARDOWN          Init
     Ready           PLAY              Playing
                     SETUP             Ready
                     TEARDOWN          Init
                     RECORD            Recording
     Playing         PLAY              Playing
                     PAUSE             Ready
                     TEARDOWN          Init
                     SETUP             Playing
     Recording       RECORD            Recording
                     PAUSE             Ready
                     TEARDOWN          Init
                     SETUP             Recording

*/
#include "base.h"
#include "RTSPSession.h"
using namespace std;

class BASE_API RTSPServerSession: public RTSPSession
{
public:
	RTSPServerSession(){};
	~RTSPServerSession(){};

protected:
	//subclass should implement this method by myself
//	int handleMessage(RTSPMessage* pMessage);
	virtual int handleMessage(RTSPRequest& request);
	virtual int handleMessage(RTSPResponse& reply);

protected:
	//deal with request from client,Server side,C->S
	//called by <handleMessage> but,implement by subclass
	void OnOptionsRequest(RTSPRequest& request){};
	void OnDescribeRequest(RTSPRequest& request){};
	void OnSetupRequest(RTSPRequest& request){};
	void OnPlayRequest(RTSPRequest& request){};
	void OnPauseRequest(RTSPRequest& request){};
	void OnRecordRequest(RTSPRequest& request){};
	void OnTeardownRequest(RTSPRequest& request){};
	//server side,C->S
	void OnRedirectReply(){};

public:
	int makeDescribeReply(int status,string &sdp,RTSPRequest& request,string& reply);
	int makeSetupReply(int status,int port,RTSPRequest& request,string& reply);
	int makePlayReply(int status,RTSPRequest& request,string& reply);
	int makePauseReply(int status,RTSPRequest& request,string& reply);
	int makeRecordReply(int status,RTSPRequest& request,string& reply);
	int makeTeardownReply(int status,RTSPRequest& request,string& reply);
	
	int makeRedirectRequest();
};

#endif